#include "TextureContainer.h"


TextureContainer* TextureContainer::instance = 0;
std::map<std::string,Texture*> TextureContainer::textures;

TextureContainer::TextureContainer(){}


void TextureContainer::destroy(){
	std::map<std::string, Texture*>::iterator it;

	for(it=TextureContainer::textures.begin();it!=TextureContainer::textures.end();it++)
		delete ((*it).second);

	if(TextureContainer::instance!=NULL)
		delete TextureContainer::instance;
	TextureContainer::instance = NULL;
}

TextureContainer::~TextureContainer(){}

TextureContainer* TextureContainer::getInstance(){
	if(!TextureContainer::instance)
		TextureContainer::instance = new TextureContainer();
	return TextureContainer::instance;
}

/****************************************************************
 * Devuelve un objeto Texture con el id figureId si no encuentra *
 * el id deberia lanzar un ObjectNotFoundExeption               *
 ***************************************************************/

Texture* TextureContainer::getTextureById(std::string textureId)throw (TextureNotFoundException){
	std::map<std::string, Texture*>::iterator it;
	it = this->textures.find(textureId);
	if(it!=this->textures.end())
		return it->second;
	throw TextureNotFoundException("No se ha encontrado la textura de id tal");
}

void TextureContainer::addTexture(Texture* texture){
	textures[texture->getId()]=texture;
}

const std::map<std::string,Texture*> TextureContainer::getAllTextures() const{
	return this->textures;
}

bool TextureContainer::existTexture(Texture* texture){
	return true;
	//	return (texture == TextureContainer::getInstance()->getTextureById(texture->getId()));
}